package com.example.main.utils;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;

import java.util.Map;

/**
 * @NAME: WSC
 * @DATE: 2021/12/9
 * @DESCRIBE:
 **/
public class WechatUtils {
    private static String url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=29d73656-e68e-4e58-8dd8-2552e3729197";

    public static boolean sendMessage(String text) {
        WeChatMessage entity = WeChatMessage.generous(text);
        String body = JSON.toJSONString(entity);

        System.out.println(body);

        String ret = HttpUtil.post(url, body);


        Map resMap = (Map) JSON.parse(ret);

        Integer reqRet = (Integer) resMap.getOrDefault("errcode", "");

        if (reqRet == 0) {
            return true;
        }else {
            return false;
        }
    }
}
